from constant import *


class Level:
    def __init__(self, screen: pg.Surface, row_property: list[Literal['unsuitable', 'grassland', 'pool', 'roof']],
                 grade_image_path='images\\interface\\background1.jpg', waves_zombies=None):
        if waves_zombies is None:
            waves_zombies = [100, 200]
        self.screen = screen
        self.lawn_lists = create_plant_lists(row_property)
        self.zombie_lists = create_zombies_list(row_property)
        self.grade = pg.image.load(grade_image_path)
        self.count_sun = CountSun(screen)
        self.random_sun = RandomSun(screen, [], self.count_sun)
        self.flag_meter = FlagMeter(screen, waves_zombies)
        self.now_zombies = 0
        self.now_wave = 0
        self.lawn_start_xy = (LAWN_START_X, LAWN_START_Y + LAWN_HEIGHT * (LAWN_ROW - len(row_property)) // 2)
        self.running = True
        self.click = pg.time.Clock()

    def run(self):
        while self.running:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    self.running = False
                elif event.type == pg.MOUSEBUTTONDOWN:
                    mouse_pos = pg.mouse.get_pos()
                    if event.button == 1:
                        self.random_sun.onclick(mouse_pos)
            self.screen.blit(self.grade, (0, 0))
            self.count_sun.update()
            self.random_sun.update()
            self.flag_meter.update(self.now_wave, self.now_zombies)
            update_plant_lists(self.lawn_lists)
            update_zombie_list(self.zombie_lists)
            update_zombies_plants(self.zombie_lists, self.lawn_lists)
            pg.display.flip()
            self.click.tick(8)


class Level1_1(Level):
    def __init__(self, screen: pg.Surface):
        super().__init__(screen, row_property=['unsuitable', 'unsuitable', 'grassland', 'unsuitable', 'unsuitable'],
                         grade_image_path='images\\interface\\background1unsodded_1.jpg', waves_zombies=[10])
        self.lawn_lists[2][0].add(Peashooter(screen, 2, 0))
        self.zombie_lists[2].add(Zombie(screen, 2))



